package io.renren.modules.substation.service.impl;

import io.renren.modules.substation.entity.*;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.substation.dao.TBusiDevStatusInfoDao;
import io.renren.modules.substation.service.TBusiDevStatusInfoService;


@Service("tBusiDevStatusInfoService")
public class TBusiDevStatusInfoServiceImpl extends ServiceImpl<TBusiDevStatusInfoDao, TBusiDevStatusInfoEntity> implements TBusiDevStatusInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String devType = (String)params.get("devType");
        String devCode = (String)params.get("devCode");
        String isAlarm = (String)params.get("isAlarm");
        String isVaild = (String)params.get("isVaild");

        IPage<TBusiDevStatusInfoEntity> page = this.page(
                new Query<TBusiDevStatusInfoEntity>().getPage(params),
                new QueryWrapper<TBusiDevStatusInfoEntity>()
                        .eq(isAlarm!=null&&!isAlarm.isEmpty(),"is_alarm",isAlarm)
                        .eq(isVaild!=null&&!isVaild.isEmpty(),"is_vaild",isVaild)
                        .eq(devCode!=null&&!devCode.isEmpty(),"dev_code",devCode)

        );

        return new PageUtils(page);
    }

    @Override
    public long queryDevShowInfoListCount(TBusiDevStatusShowInfo tBusiDevStatusShowInfo)
    {
        return (long) baseMapper.queryDevShowInfoListCount(tBusiDevStatusShowInfo);
    }

    @Override
    public List<TBusiDevStatusShowInfo> queryDevShowInfoList(TBusiDevStatusShowInfo tBusiDevStatusShowInfo)
    {

        return (List<TBusiDevStatusShowInfo>) baseMapper.queryDevShowInfoList(tBusiDevStatusShowInfo);
    }

    @Override
    public  List<DevDetailInfo> queryDevDetailInfoByCondition(DevDetailInfo devDetailInfo)
    {
        return (List<DevDetailInfo>) baseMapper.queryDevDetailInfoByCondition(devDetailInfo);
    }

    @Override
    public int countAllDevNum() {
        return baseMapper.countAllDevNum();
    }

    @Override
    public int countErrorDevNum() {
        return baseMapper.countErrorDevNum();
    }

    @Override
    public int updateByCode(TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity)
    {
        return baseMapper.updateByCode(tBusiDevStatusInfoEntity);
    }

    @Override
    public int countAllDevNumBySta(Map<String, Object> params) {
        return baseMapper.countAllDevNumBySta(params);
    }

    @Override
    public int countOfflineDevNumBySta(Map<String, Object> params) {
        return baseMapper.countOfflineDevNumBySta(params);
    }

    @Override
    public  int updateDevStatusInfoByCode (TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity)
    {
        return baseMapper.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
    }

    @Override
    public int countAllDevNumByArea(String subAreaStr) {
        Map<String, Object> params = new HashMap<>();
        params.put("subAreaStr", subAreaStr);
        return baseMapper.countAllDevNumByArea(params);
    }

    @Override
    public int countOfflineDevNumByArea(String subAreaStr) {
        Map<String, Object> params = new HashMap<>();
        params.put("subAreaStr", subAreaStr);
        return baseMapper.countOfflineDevNumByArea(params);
    }

    @Override
    public List<TBusiDevStatusInfoEntity> countAllDevNumGroup() {
        return baseMapper.countAllDevNumGroup();
    }

    @Override
    public List<TBusiDevStatusInfoEntity> countOfflineDevNumGroup() {
        return baseMapper.countOfflineDevNumGroup();
    }

    @Override
    public String getAreaChildList(Map<String, Object> params) {
        return baseMapper.getAreaChildList(params);
    }

    @Override
    public int updateDevHealthStatus(String devCode, String status) {
        TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity = new TBusiDevStatusInfoEntity();
        tBusiDevStatusInfoEntity.setDevCode(devCode);
        tBusiDevStatusInfoEntity.setIsAlarm(status);
        tBusiDevStatusInfoEntity.setLastOpr((long)0);
        tBusiDevStatusInfoEntity.setLastTime(new Date());
        return baseMapper.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
    }

    @Override
    public List<TBusiDevAutoReportSumInfo> queryAutoReportSumList(TBusiDevAutoReportSumInfo tBusiDevAutoReportSumInfo)
    {
        return baseMapper.queryAutoReportSumList(tBusiDevAutoReportSumInfo);
    }

    @Override
    public List<TBusiDevAutoReportInfo> queryPdAutoReportList(TBusiDevAutoReportInfo tBusiDevAutoReportInfo)
    {
        return baseMapper.queryPdAutoReportList(tBusiDevAutoReportInfo);
    }
}